<template>
  <div id="wrapper">
    <header class="title">心玲图片压缩!</header>
    <main>
      <div class="left-side">
        <div class="title">文件列表</div>
        <button @click="open('https://simulatedgreg.gitbooks.io/electron-vue/content/')" class="open">选择文件夹</button>
      </div>
      <div class="right-side">
        <div class="doc">
          <div class="title">Getting Started</div>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import SystemInformation from './LandingPage/SystemInformation'
import imgModule from '@/assets/module/imgModule.js'
const fs = require('fs')

export default {
  name: 'landing-page',
  components: { SystemInformation },
  methods: {
    open(link) {
      this.$electron.ipcRenderer.send('open-directory-dialog', [
        'openFile',
        'openDirectory'
      ])
    },
    openFolder(url) {
      console.log(
        'TCL: openFolder -> url',
        imgModule,
        `${url}\\1.jpg`,
        `${url}-temp\\1.jpg`
      )
      // const shell = this.$electron.shell
      // let res = shell.showItemInFolder(url)
      let files = fs.readdirSync(url)
      files.forEach((element, index) => {
        console.log('TCL: openFolder -> element', element)
        // imgModule.compass(`${url}\\1.jpg`, `${url}-temp`)
      })
    },
    lister() {
      this.$electron.ipcRenderer.on(
        'open-directory-dialog-reply',
        (event, arg) => {
          this.openFolder(arg)
        }
      )
    }
  },
  mounted() {
    this.lister()
  }
}
</script>

<style>
@import url('https://fonts.googleapis.com/css?family=Source+Sans+Pro');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Source Sans Pro', sans-serif;
}

#wrapper {
  background: radial-gradient(
    ellipse at top left,
    rgba(255, 255, 255, 1) 40%,
    rgba(229, 229, 229, 0.9) 100%
  );
  height: 100vh;
  padding: 20px 40px;
  width: 100vw;
}

#logo {
  height: auto;
  margin-bottom: 20px;
  width: 420px;
}

main {
  display: flex;
  justify-content: space-between;
}

main > div {
  flex-basis: 50%;
}

.left-side {
  display: flex;
  flex-direction: column;
}

.welcome {
  color: #555;
  font-size: 23px;
  margin-bottom: 10px;
}

.title {
  color: #2c3e50;
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 6px;
}

.title.alt {
  font-size: 18px;
  margin-bottom: 10px;
}

.doc p {
  color: black;
  margin-bottom: 10px;
}

button.open {
  font-size: 0.8em;
  cursor: pointer;
  outline: none;
  padding: 0.75em 2em;
  border-radius: 2em;
  display: inline-block;
  color: #fff;
  background-color: #4fc08d;
  transition: all 0.15s ease;
  box-sizing: border-box;
  border: 1px solid #4fc08d;
  width: 200px;
}

.doc button.alt {
  color: #42b983;
  background-color: transparent;
}
</style>
